#include <iostream>
#include <vector>

using namespace std;

int maxProfit(vector<int>& prices) {
    int ret = 0;
    for (int i = 0, prevMin = INT_MAX; i < prices.size(); ++i)
    {
        ret = max(ret, prices[i] - prevMin);
        prevMin = min(prevMin, prices[i]);
    }
    return ret;
}

int maxProfit(vector<int>& prices) {
    /*int ret = 0, n = prices.size();

    for (int i = 0; i < n; ++i)
    {
        int j = i;
        while (j + 1 < n && prices[j + 1] > prices[j])
            ++j;
        ret += prices[j] - prices[i];
        i = j;
    }

    return ret;*/

    int ret = 0, n = prices.size();

    for (int i = 0; i < n; ++i)
    {
        int j = i;
        while (j + 1 < n && prices[j + 1] > prices[j])
            ++j;
        ret += prices[j] - prices[i];
        i = j;
    }

    return ret;
        
}

int main()
{

	return 0;
}